package Interview;

import java.util.Scanner;
public class _wanmei_2017329Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {//注意while处理多个case
            int numOfP = in.nextInt();
            int[] values = new int[numOfP];
            int[] heaves = new int[numOfP];
            for (int i = 0; i < numOfP; i++) {
                values[i] = in.nextInt();
            }
            for (int i = 0; i < numOfP; i++) {
                heaves[i] = in.nextInt();
            }
            int maxheave = in.nextInt();

            int c[][] = new int[numOfP+1][maxheave+1];
            for (int i = 0; i < numOfP + 1; i++) {
                c[i][0] = 0;
            }
            for (int i = 0; i < maxheave+1; i++) {
                c[0][i] = 0;
            }

            for (int i = 1; i < numOfP + 1; i++) {
                for (int j = 1; j < maxheave + 1; j++) {
                    if (heaves[i-1] <= j){
                        if(c[i-1][j] < (c[i-1][j-heaves[i-1]]+values[i-1])){
                            c[i][j] = c[i-1][j-heaves[i-1]] + values[i-1];
                        }
                        else{
                            c[i][j] = c[i-1][j];
                        }
                    }
                    else{
                        c[i][j] = c[i-1][j];
                    }

                }
            }
            System.out.println(c[numOfP][maxheave]);
        }
    }

}
